{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<link href="{__STATIC__}/home/other/formSelects-v4.css" rel="stylesheet" />
<script src="{__STATIC__}/home/other/jquery.min.js"></script>
<script src="{__STATIC__}/home/other/formSelects-v4.min.js"></script>

<form class="layui-form p-4">
    <h3 class="pb-3">功能菜单/节点</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray">品名<font>*</font>
            </td>
            <td>
                <input type="text" name="name" value="{$detail.name|default=''}" lay-verify="required"
                       autocomplete="off" placeholder="请输入名称"
                       lay-reqText="请输入物料名称" class="layui-input">
            </td>
            <td class="layui-td-gray">品牌
            </td>
            <td style="display: flex">
                <select name="brand1" class="layui-select" lay-search lay-filter="brand1">
                    <option value="无">无</option>
                    {volist name='pinpaiList' id='ppl'}
                    <option value="{$ppl}" {if isset($detail.brand) &&$detail.brand ==$ppl} selected {/if}>{$ppl}</option>
                    {/volist}
                </select>
                <input type="text" name="brand" value="" id="brand"
                       autocomplete="off" placeholder="请输入品牌"
                       lay-reqText="请输入品牌" class="layui-input" style="display: flex">
            </td>
            <td class="layui-td-gray">分类<font>*</font>
            </td>
            <td>
                <select name="type" >
                    {volist name='typeList' id='tl'}
                    <option value="{$tl.id}" {if isset($detail.type)&&$detail.type== $tl.id} selected {/if} >{$tl.title}</option>
                    {/volist}
                </select>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">型号<font>*</font>
            </td>
            <td>
                <input type="text" name="specs" value="{$detail.specs|default=''}" lay-verify="required"
                       autocomplete="off" placeholder="请输入型号"
                       lay-reqText="请输入型号" class="layui-input">
            </td>
            <td class="layui-td-gray">订货号
            </td>
            <td>
                <input type="text" name="buyCode" value="{$detail.buyCode|default=''}"
                       autocomplete="off" placeholder="请输入"
                       lay-reqText="请输入" class="layui-input">
            </td>
            <td class="layui-td-gray">税收编码
            </td>
            <td>
                <input type="text" name="taxCode" value="{$detail.taxCode|default=''}"
                       autocomplete="off" placeholder="请输入"
                       lay-reqText="请输入" class="layui-input">

            </td>

        </tr>

        <tr>
            <td class="layui-td-gray">产品面价
            </td>
            <td>
                <input type="text" name="proPrice" value="{$detail.proPrice|default=''}"
                       autocomplete="off" placeholder="请输入"
                       lay-reqText="请输入" class="layui-input" oninput="digitalFiltering(this,2)">
            </td>
            <td class="layui-td-gray">计量单位<font>*</font>
            </td>
            <td>
                <input type="text" name="unit" value="{$detail.unit|default=''}" lay-verify="required"
                       autocomplete="off" placeholder="请输入单位"
                       lay-reqText="请输入单位" class="layui-input">
            </td>
            <td class="layui-td-gray">状态<font>*</font>
            </td>
            <td>
                <select name="status" >
               {foreach [['id'=>1,'name'=>'启用'],['id'=>2,'name'=>'禁用']] as $st}
                    <option value="{$st.id}" {if isset($detail.status)&&$detail.status==$st.id } selected {/if}>{$st.name}</option>
                    {/foreach}
                </select>

            </td>

        </tr>

<!--        <tr>-->
<!--            <td class="layui-td-gray">可用于<font>*</font>-->
<!--            </td>-->
<!--            <td>-->

<!--                <select name="useType" xm-select="selectId">-->
<!--                    {foreach ['销售','采购','生产'] as $st}-->
<!--                    <option value="{$st}" {if isset($detail.useType)&&in_array($st,explode(',',$detail.useType))} selected {/if}>{$st}</option>-->
<!--                    {/foreach}-->
<!--                </select>-->

<!--            </td>-->

<!--        </tr>-->
        <tr>
            <td class="layui-td-gray">备注 </td>
            <td>
                <input type="text" name="remark" value="{$detail.remark|default=''}"
                       autocomplete="off" placeholder="请输入备注"
                       lay-reqText="请输入备注" class="layui-input">
            </td>
<!--            <td class="layui-td-gray">存货类别<font>*</font>-->
<!--            </td>-->
<!--            <td>-->
<!--                <select name="stock_type" >-->
<!--                    {foreach ['成品','半成品','原材料'] as $st}-->
<!--                    <option value="{$st}" {if isset($detail.stock_type)&&$detail.stock_type==$st } selected {/if}>{$st}</option>-->
<!--                    {/foreach}-->
<!--                </select>-->
<!--            </td>-->
            <td class="layui-td-gray">库存下限
            </td>
            <td>
                <input type="number" min="0" max="999999" name="stock_min" value="{$detail.stock_min|default='0'}"
                       autocomplete="off" placeholder="请输入库存下限"
                       lay-reqText="请输入库存下限" class="layui-input">
            </td>
            <td class="layui-td-gray">库存上限
            </td>
            <td>
                <input type="number" min="0" max="999999" name="stock_max" value="{$detail.stock_max|default='0'}"
                       autocomplete="off"  placeholder="请输入库存上限"
                       lay-reqText="请输入库存上限" class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">编码<font>*</font>
            </td>
            <td>
                <input type="text" name="bar_code" readonly value="{$detail.bar_code|default=''}" lay-verify="required"
                       autocomplete="off" placeholder="请输入编码"
                       lay-reqText="请输入编码" class="layui-input">
            </td>
            <td class="layui-td-gray">默认仓库<font>*</font>
            </td>
            <td>
                <select name="warehouse_id" id="warehouse_id" lay-filter="warehouse_id">
                    <option value="">请选择</option>
                    {volist name='warehouse' id='wh'}
                    <option value="{$wh.id}" {if isset($detail.warehouse_id)&&$detail.warehouse_id==$wh.id} selected {/if}>{$wh.name}</option>
                    {/volist}
                </select>
            </td>
            <td class="layui-td-gray">默认库位
            </td>
            <td>
                <select name="warehouse_detail_id" id="warehouse_detail_id">
                    {if isset($detail.cangwei)}
                    {volist name='$detail.cangwei' id='cw'}
                    <option value="{$cw.id}" {if $detail.warehouse_detail_id == $cw.id} selected {/if}>{$cw.name}</option>
                    {/volist}
                    {/if}
                </select>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray">图片(最多15张)
            </td>
            <td colspan="6">
                <div style="display:  flex">
                    <input type="hidden" name="img" limit="15" id="img" value="{$detail.img|default=''}">
                </div>

            </td>
        </tr>
    </table>
    <div class="py-3">
        <input type="hidden" name="id" value="{$id}">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script type="text/javascript">
    formSelects.render('selectId');
</script>
<script>
    const moduleInit = ['tool'];
    let detailBrand="{$detail.brand|default='无'}"
    function gouguInit() {
        var form = layui.form, tool = layui.tool, level = 0,upload = layui.upload;
        level = $('[name="pid"]').find('[selected=""]').attr('title');
        if (level === undefined) {
            level = 0;
        }
        //监听提交
        form.on('submit(webform)', function (data) {
            form.on('select(pid)', function (data) {
                level = data.elem[data.elem.selectedIndex].title;
            })
            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    setTimeout(function () {
                        parent.parent.location.reload();
                    }, 1000);
                }
            }
            tool.post("/home/MaterialDossier/add", data.field, callback);
            return false;
        });
        form.on('select(warehouse_id)', function (data) {
            var wid=data.value;

            $("#warehouse_detail_id").empty();
            var optionStr='';
            if (wid!=''){
                $.ajax({
                    url:'/home/api/getWarHoseDetail',
                    type:'post',
                    dataType:'json',
                    data:{id:wid},
                    success:function (res) {
                        if (res.code==0){
                            let data=res.data;
                            for(var i=0;i<data.length;i++){
                                optionStr+=" <option value='"+data[i].id+"'>"+data[i].name+"</option>";
                            }
                        }else {
                            optionStr+=" <option value=''>暂无数据</option>";
                        }
                        $("#warehouse_detail_id").append(optionStr);
                        form.render();
                    }

                })
            }else {
                optionStr+=" <option value=''>请选择仓库</option>";
                $("#warehouse_detail_id").append(optionStr);
                form.render();
            }


        }); // select(lay-filter属性的值)
        layui.use(['form'], function () {
            var form = layui.form;
            form.render();
        });
uploadFiles('#img')

        form.on('select(brand1)', function (data) {
           let val=data.value;
           pinpaiDo(val);
        })

        pinpaiDo(detailBrand);
    }
    function pinpaiDo(text='无') {

        if (text=='无'){
            $('#brand').val('');
            $('#brand').removeAttr("disabled")
        }else {
            $('#brand').val('');
            $('#brand').attr("disabled", "disabled")
        }
    }
</script>
{/block}
<!-- /脚本 -->